<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
{literal}
/* popup_box DIV-Styles*/
#popup_box,#popup_box1 { 
	display:none; /* Hide the DIV */
	position:fixed;  
	_position:absolute; /* hack for internet explorer 6 */  
	height:460px;  
	width:400px;  
	background:#FFFFFF;  
	left: 300px;
	top: 50px;
	z-index:100; /* Layering ( on-top of others), if you have lots of layers: I just maximized, you can change it yourself */
	margin-left: 15px;  
	
	/* additional features, can be omitted */
	border:2px solid #ffffff;  	
	padding:15px;  
	font-size:15px;  
	-moz-box-shadow: 0 0 5px #ff0000;
	-webkit-box-shadow: 0 0 5px #ff0000;
	box-shadow: 0 0 10px #123456;
	
}



a{  
cursor: pointer;  
text-decoration:none;  
} 

/* This is for the positioning of the Close Link */
#popupBoxClose {
	font-size:20px;  
	line-height:15px;  
	right:5px;  
	top:5px;  
	position:absolute;  
	color:#6fa5e2;  
	font-weight:500;  	
}
{/literal}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/flexigrid.css" />


<script type="text/javascript" src="js/jquery-1.2.3.pack.js"></script>
<script type="text/javascript" src="js/flexigrid.js"></script>

<script type="text/javascript">
{literal}
function doClick()
{
   var form1 = document.d1;
   /*
   *need to add panduan
   */
   form1.action = '?act=product.add_product';
   form1.submit();
	
	
}


function doClick1()
{
	var pid = document.getElementById("productID").value;

	var form1 = document.d2;
	
	itemlist = pid+ form1.number.value+",";
	
	
	 $.ajax({
		   type: "POST",
		   dataType: "json",
		   url: "?act=discount.product_add_discount",
		   data: "items="+itemlist,
		   success: function(){
		   unloadPopupBox();
		   alert("添加成功！");
		   unloadPopupBox('#popup_box1'); 
		   $("#flex1").flexReload();
		   }
		 });
}
function loadPopupBox(name) 
{	// To Load the Popupbox
	$(name).fadeIn("slow");
		
}

function unloadPopupBox(name) 
{	// TO Unload the Popupbox
	$(name).fadeOut("slow");
	
}
$(document).ready(function(){
	
	$("#flex1").flexigrid
			(
			{
				url: '?act=product.product_list_show',
				dataType: 'json',

			colModel : [
				{display: 'ID', name : 'ID', width : 40, sortable : true, align: 'center'},
				{display: 'Name', name : 'Name', width : 240, sortable : true, align: 'center'},
				{display: 'Publisher', name : 'Publisher', width : 200, sortable : true, align: 'left'},
				{display: 'Quantity', name : 'Quantity', width : 40, sortable : true, align: 'left'},
				{display: 'Price', name : 'Price', width : 40, sortable : true, align: 'left'},
				{display: 'Category', name : 'Category', width : 180, sortable : true, align: 'left'},
				{display: 'ISBN', name : 'ISBN', width : 200, sortable : true, align: 'left'},
				
				
				],
			buttons : [
				{name: 'Add', bclass: 'add', onpress : test},
				{name: 'Delete', bclass: 'delete', onpress : test},
				{name: 'AddDiscount', bclass:'add' ,onpress : test},
				{name: 'Export', bclass: 'export', onpress : test}
				],
				searchitems : [
								
								{display: 'Name', name : 'a.Name', isdefault: true},
								{display: 'Publisher', name : 'Publisher'},
								{display: 'Category', name : 'Category'}

								],
			sortname: "id",
			sortorder: "asc",
			usepager: true,
			title: '商品信息',
			useRp: true,
			rp: 20,
			nomsg: '没有符合条件的记录存在', 
			showTableToggleBtn: true,
			width: 'auto',
			height: 'auto',
			procmsg: '正在获取数据，请稍候 ...'  
			}
			);   
	
});
function sortAlpha(com)
{ 
    jQuery('#flex1').flexOptions({newp:1, params:[{name:'letter_pressed', value: com},{name:'qtype',value:$('select[name=qtype]').val()}]});
    jQuery("#flex1").flexReload(); 
}

function test(com,grid)
{
    if (com=='Delete')
        {
    	   if($('.trSelected',grid).length>0){
    		   if(confirm('Delete ' + $('.trSelected',grid).length + ' items?')){
    		 
    			var tmp ='';
                
                for(var i=0;i<$('.trSelected',grid).length;i++)
                {  
             		var a = $('.trSelected',grid).find("td:first").eq(i).text();
                	tmp =tmp+a+",";
 	 
    			}
              
			$.ajax({
			   type: "POST",
			   dataType: "json",
			   url: "?act=product.product_delete",
			   data: "items="+tmp,
			   success: function(data){
			   alert("删除成功");
			   $("#flex1").flexReload();
			   }
			 });
			}
			} else {
				return false;
			} 
        }
    else if (com=='Add')
        {
    	  loadPopupBox('#popup_box');  
        }  
    else if(com=='AddDiscount')
    	{
    	if($('.trSelected',grid).length>0){
 		   if(confirm('为这' + $('.trSelected',grid).length + '个书籍增加优惠?')){
 		 
 			var tmp ='';
             
             for(var i=0;i<$('.trSelected',grid).length;i++)
             {  
          		var a = $('.trSelected',grid).find("td:first").eq(i).text();
             	tmp =tmp+a+",";
	 
 			}
             var pid = document.getElementById("productID");
             pid.value = tmp;
             
           
            $.ajax({
 			   type: "POST",
 			   dataType: "json",
 			   url: "?act=discount.discount_list_show",
 			   data: {page:1},
 			   success: function(data){
 			  // alert(data.rows[0]['cell'][2]);
 			  if(document.getElementById('dt').childNodes.length>1)
			    	 {
						document.getElementById('dt').removeChild(document.getElementById('dt').childNodes[1]);
			    	 }
				 var table=document.createElement("table");
				   
				
				 for(var i=0;i<data.rows.length;i++)
				   {
				   		var row=table.insertRow();
				   	
				   		var cell=row.insertCell();
						cell.innerText=data.rows[i]['cell'][4];
						
						var cell=row.insertCell();
						cell.innerText=data.rows[i]['cell'][2];
						
						var cell=row.insertCell();
						
						cell.innerText=data.rows[i]['cell'][0];
						  
				   	    
				   	}	   
				 
					 var row=table.insertRow(); 
					 
					 var cell=row.insertCell();
					     cell.innerText='优惠';
					 
					 var cell=row.insertCell();
					     cell.innerText='内容';
					 
					 var cell=row.insertCell();
					     cell.innerText='序号';
				   
                   var div =document.getElementById('dt');
				   div.appendChild(table); 
 			  
				   loadPopupBox('#popup_box1');
 			//  $("#flex1").flexReload();
 			   }
 			 });
			}
			}
    	  
    	}
    else if (com=='Export')
    	{
    		window.open("?act=product.export_product");
    	}
} 
{/literal}
</script>
<title>Insert title here</title>
</head>
<body>
<div>
<table id="flex1" style="display:none"></table>
</div>
<div id="popup_box">	<!-- OUR PopupBox DIV-->
	<h2>增加商品</h2>
<form name="d1" action="" method="POST" enctype="multipart/form-data">
<table align="center">
<tr><td>
<input type="hidden" id="productID" value=""/>
</td>
</tr>
<tr>
<td>名称</td>
<td><input type="text" value="" name="name"></input></td>
</tr>
<tr>
<td>出版社</td>
<td><input type="text" value="" name="publisher"></input></td>
</tr>
<tr>
<td>总页数</td>
<td><input type="text" value="" name="totalpage"></input></td>
</tr>
<tr>
<td>描述</td>
<td><input type="text" value="" name="description"></input></td>
</tr>
<tr>
<td>语言</td>
<td><input type="text" value="" name="prolang"></input></td>
</tr>
<tr>
<td>作者</td>
<td><input type="text" value="" name="author"></input></td>
</tr>
<tr>
<td>库存</td>
<td><input type="text" value="" name="quantity"></input></td>
</tr>
<tr>
<td>价格</td>
<td><input type="text" value="" name="price"></input></td>
</tr>
<tr>
<td>ISBN</td>
<td><input type="text" value="" name="isbn"></input></td>
</tr>
<tr>
<td>种类</td>
<td><input type="text" value="" name="category"></input></td>
</tr>
<tr>
<td>图片</td>
<td><input id="fileToUpload" type="file" size="45" name="file" ></td>
</tr>
</table>
<br>
<br>	
	<input type="button" value="提交" onClick="doClick()"/>
	</form>
	<a id="popupBoxClose" onClick="unloadPopupBox('#popup_box')">Close</a>	
</div>

<div id="popup_box1">	<!-- OUR PopupBox DIV-->
	<h1> 增加优惠</h1>
	     <div id="dt">
</div>
	<form name="d2" action="?act=discount.modify_quantity" method='post'>
<table>
<tr><td>
<input type="hidden" id="productID" value=""/>
</td>
</tr>
<tr>
<td>请输入优惠的序号：</td>
<td><input type="text" value="" name="number"></input></td>
</tr>
</table>
<br>
<br>	
	<input type="button" value="提交" onClick="doClick1();">
	</form>
	<a id="popupBoxClose" onClick="unloadPopupBox('#popup_box1')">Close</a>	
</div>
</body>
</html>